package org.grizz.game.entities;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class MovingPoint implements Updateable {
	private Vector2 location;
	private Vector2 speed;

	@Override
	public void update(float delta) {
		location.x += delta * speed.x;
		location.y += delta * speed.y;
	}
	
	public void bounceInside(Rectangle area) {
		bounceInside(area.x, area.x + area.width, area.y, area.y + area.height);
	}
	
	public void bounceInside(float minX, float maxX, float minY, float maxY) {
		if(location.x < minX) {
			speed.x = Math.abs(speed.x);
		}
		
		if(location.x > maxX) {
			speed.x = -Math.abs(speed.x);
		}
		
		if(location.y < minY) {
			speed.y = Math.abs(speed.y);
		}
		
		if(location.y > maxY) {
			speed.y = -Math.abs(speed.y);
		}
	}
	
	public void move(float delta) {
		location.x += delta * speed.x;
		location.y += delta * speed.y;
	}

	public MovingPoint setSpeed(Vector2 speed) {
		this.speed = speed;
		return this;
	}
	
	public MovingPoint setLocation(Vector2 location) {
		this.location = location;
		return this;
	}
	
	public Vector2 getSpeed() {
		return speed;
	}
	
	public Vector2 getLocation() {
		return location;
	}

}
